// pages/free/free.js
var a;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_new_user: false,
    page_url: '',
    surprise: '',
    remind: false,
    task: [],
    msgList: [],
    lb: ['https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F89746ec4a713cc0623b423385a8ca52cf8657657.png','https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F734028af78b76c0adffc1f7a5afe82482f0e5546.png'],
    vertical: false,
    autoplay: true,
    circular: true,
    interval: 4000,
    duration: 500,
    user_info: {},
    sssid: 0,
    list: [],
    opren:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  LiveInfo:function(e){
    console.log('zhibojinlai')
    wx.navigateTo({
      url: '/pages/pluginprivate/pluginprivate',
    })
    // var opren = this.data.opren
    //       if(opren.status  == 2){
    //         wx.openChannelsActivity({
    //           finderUserName:'sphlAvG4O3eSXGd',
    //           feedId:opren.feedId,
    //           complete:(r) => {
    //             console.log('11112222',r)
    //           }
    //         })
    //       }else{

    //       }
  },
  onLoad: function (t) {

    getApp().page.onLoad(this, t);
    a = this
    if (t.remind) {
      a.setData({
        remind: t.remind
      })
    }
    if (wx.getStorageSync('ACCESS_TOKEN')) {
      console.log('已登录')
      if (t.recommender_id) {
        console.log('1')
        getApp().page.bindParent1(t.recommender_id)
      } else {
        console.log('2')
      }
    } else {
      console.log('未登录')
      var recommender_id = wx.getStorageSync('recommender_id')
      console.log('recommender_id==', recommender_id)
      if (t.recommender_id) {
        if (recommender_id === '' || recommender_id === '0') {
          console.log('wu')
          wx.setStorageSync('recommender_id', t.recommender_id)
        } else {
          console.log('you')
        }
      }
    }
    a.user_status()
    // a.msg_notiction()
    getApp().request({
      url: getApp().api.integral.index,
      data: {},
      success: function (t) {
        if (t.code == 0) {

          if (t.data.user == null) {
            a.setData({
              // banner_list: t.data.banner_list,
              coupon_list: t.data.coupon_list,
              catList: t.data.cat_list,
              promotion: t.data.promotion,
              page_url: t.data.promotion.page_url,
              pro_url: t.data.promotion.pro_url,
              surprise: t.data.activity,

            })
          } else {
            a.setData({
              // banner_list: t.data.banner_list,
              coupon_list: t.data.coupon_list,
              integral: t.data.user.integral,
              catList: t.data.cat_list,
              promotion: t.data.promotion,
              page_url: t.data.promotion.page_url,
              pro_url: t.data.promotion.pro_url,
              surprise: t.data.activity,
              is_distributor: t.data.user.is_distributor,
            })
          }
          var sssid = t.data.activity.page_url.substring(28)
          a.supindex(sssid)
        }
      },
      complete: function (t) {
        getApp().core.hideLoading();
      }
    });
  },
  user_status: function (e) {
    var o = this
     getApp().request({
       url: getApp().api.default.user_status,
       success: function (e) {
         o.setData({
           is_new_user: e.data.is_new_user
         })
       },
       complete: function () {
         getApp().core.hideLoading();
       }
     });
   },
  userindex: function (e) {
    getApp().request({
      url: getApp().api.user.index,
      success: function (o) {
        if (0 == o.code) {
          a.setData({
            user_info: o.data.user_info
          })
        }
      }
    });
  },
  goodsInfo: function (e) {
    console.log(e)
    var that = this
    var id = e.currentTarget.dataset.goodsId
    var goods_num = e.currentTarget.dataset.goods_num
    var lgs_id = e.currentTarget.dataset.lgs_id
    if (!that.data.is_new_user) {
      getApp().core.showModal({
        title: '您还未成为99会员，点击确认即可成为99会员。',
        success: function (e) {
          e.confirm && (wx.navigateTo({
            url: '/pages/Nineactivities/Nineactivities',
          }))
        }
      })
      return;
    }
    if (goods_num == '0') {
      getApp().core.showToast({
        title: "此商品已售罄",
        icon: "none"
      })
    } else {
      console.log(that.data.time < that.data.start_time)
      if (that.data.time < that.data.start_time) {
        getApp().core.showToast({
          title: "活动未开始，开始时间为" + that.data.start_time,
          icon: "none"
        })
      } else {
        if (that.data.time > that.data.end_time) {
          getApp().core.showToast({
            title: "活动已结束",
            icon: "none"
          })
        } else {
          console.log(that.data.id)
          wx.navigateTo({
            url: '/pages/exchange-details/exchange-details?goods_id=' + id + '&aid=' +'8' + '&lgs_id=' + lgs_id,
          })
        }
      }
    }

  },
  supindex: function (e) {
    var list = a.data.list
    getApp().request({
      url: getApp().api.surprise.exchange_index,
      data: {
        aid: e,
      },
      success: function (t) {
        console.log(t)
        if (t.code == 0) {
          for (var i = 0; i < t.data.list.length; i++) {
            t.data.list[i].exchange_attr = JSON.parse(t.data.list[i].exchange_attr)
            list.push(t.data.list[i])
          }
          console.log('list', list)
          a.setData({
            list: list,
            totalCount: t.data.pagination.totalCount,
            start_time: t.data.setting.start_time,
            end_time: t.data.setting.end_time
          })
        } else {
          a.setData({
            list: [],

          })
        }

      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  daily_task: function (e) {
    var a = this
    getApp().request({
      url: getApp().api.default.daily_task,
      success: function (t) {
        console.log(t)
        if (t.code == 0) {
          a.setData({
            task: t.data
          })
        }
      },
      complete: function (t) {
        getApp().core.hideLoading();
      }
    });
  },
  msg_notiction: function (e) {
    var a = this
    getApp().request({
      url: getApp().api.integral_lottery.msg_notiction,
      success: function (t) {
        console.log(t)
        if (t.code == 0) {
          a.setData({
            msgList: t.data.list
          })
        }
      },
      complete: function (t) {
        getApp().core.hideLoading();
      }
    });
  },
  onShow: function (e) {
    var a = this
    getApp().page.onShow(this),
      a.daily_task(), a.userindex()
  },
  register: function () {
    var a = this
    getApp().core.navigateTo({
      url: a.data.page_url
    });
  },
  surprise: function (e) {
    var a = this
    getApp().core.navigateTo({
      url: a.data.surprise.page_url
    });
  },
  luck_draw: function (e) {
    wx.navigateTo({
      url: '/pages/luck-draw/luck-draw',
    })
  },
  surprise1: function (e) {
    getApp().core.showToast({
      title: "暂未开启超惊喜",
      icon: "none"
    })
  },
  thumbsup: function (e) {
    console.log(e)
    var free = e.currentTarget.dataset.free
    wx.navigateTo({
      url: '/pages/tuibao-integral-mall/thumbsup/thumbsup?id=38' + '&free=' + free,
    })
  },
  thumbsup1: function (e) {
    wx.showModal({
      title: '提示',
      content: '去通知好友转发给自己点赞得爱心吧！',
      showCancel: false,
    })

  },
  thumbsup2: function (e) {
    wx.showModal({
      title: '提示',
      content: '把视频转发给好友，提醒他们看视频点爱心，2个人都可以获得爱心哟!',
      showCancel: false,
    })

  },
  kp: function (e) {
    var a = this
    a.setData({
      remind: true
    }),
      a.daily_task()
  },
  guanb: function (e) {
    var a = this
    a.setData({
      remind: false
    })
  },
  bargainlist: function (e) {
    wx.navigateTo({
      url: '/bargain/list/list',
    })
  },
  //转发
  onShareAppMessage: function () {
    var t = getApp().getUser()
    getApp().page.onShareAppMessage(this);
    return {
      path: "/pages/free/free?recommender_id=" + t.id,
      title: '超免费',
      imageUrl: 'https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2Fd96200a17a430ac7cc8921c4b88d5c9a31b9a319.jpg'
    };
  },

})